home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swagd_f.zip / DATATYPE.SWG / 0003_BOOLS.PAS.pas < prev    next >
Pascal/Delphi Source File  |  1993-05-28  |  2KB  |  66 lines

  1. {
  2.   This is a small Unit I wrote when I got tired of writing great gobs
  3.   of nested "if thens" or pages of parenthetic blobs.
  4.   With this Unit you can Write as many Boolean expressions
  5.   as you like as a block of Boolean.
  6.   True mode:
  7.        all interior expressions must be True For the block to be True.
  8.        if one interior expression is False then the block is False.
  9.   False mode:
  10.        all interior expressions must be False For the block to be False.
  11.        if one interior expression is True then the block is True.
  12.   Any ideas on enhancing it?
  13. }
  14. Uses
  15.   Crt;
  16.  
  17. Const
  18.   AllBool  : Boolean = True;
  19.   BoolMode : Boolean = True;
  20.  
  21. Var
  22.   S : String;
  23.  
  24. Procedure SetBool(Mode : Boolean);
  25. begin
  26.   AllBool  := Mode;
  27.   BoolMode := Mode;
  28. end;
  29.  
  30. Procedure Bool(Expression : Boolean);
  31. begin
  32.   if ((BoolMode) and (not Expression)) then
  33.     AllBool := False;
  34.   if ((not BoolMode) and (Expression)) then
  35.     AllBool := True;
  36. end;
  37.  
  38. begin
  39.   ClrScr;
  40.   S := '1 This is the best there is \.';      {init. String}
  41.   SetBool(True);                {set checkmode For all True}
  42.   Bool( Length(s) > 4 );        {series of Boolean expressions}
  43.   Bool( s[3] in ['A'..'Z'] );
  44.   Bool( Ord(s[1]) - 48 < 10 );
  45.   Bool( Pos('This', s) > 0 );
  46.   Bool( s[Length(s)] = '.');
  47.   Bool( 2 + 3 = 5);
  48.   if AllBool then
  49.     Writeln('1. All expressions are True')
  50.   else
  51.     Writeln('1. At least one expression is False');
  52.  
  53.   SetBool(False);              {set checkmode For all False}
  54.   Bool( Length(s) > 44 );      {series of Boolean expressions}
  55.   Bool( s[3] in ['a'..'z'] );
  56.   Bool( Ord(s[1]) - 48 > 10 );
  57.   Bool( Pos('This', s) = 0 );
  58.   Bool( s[Length(s)] = 'g');
  59.   Bool( 2 + 3 = 4);
  60.   if not AllBool then
  61.     Writeln('2. All expressions are False')
  62.   else
  63.     Writeln('2. At least one expression is True');
  64.   Readln;
  65. end.
  66.